import datetime

import numpy
from PIL import Image, ImageFont, ImageDraw
import cv2
import re


def get_now_datetime():
    now = datetime.datetime.now()
    return str(now.strftime("%Y-%m-%d %H:%M:%S"))


def work():
    fontpath = "font/simsun.ttc"
    font = ImageFont.truetype(fontpath, 128)
    index = 1
    while 1:
        frame = cv2.imread('img1/' + str(index) + '.jpg')
        img_pil = Image.fromarray(frame)
        draw = ImageDraw.Draw(img_pil)
        # draw.text((img_width / 5 * 3, img_height - 250), "更新时间：" + str(get_now_datetime()), font=font, fill=(0, 255, 0))
        # draw.text((img_width / 5 * 3, img_height - 250), "更新时间：2022-08-23 16:32:53", font=font, fill=(0, 255, 0))
        draw.text((0, 0), "更新时间：" + str(get_now_datetime()), font=font, fill=(0, 255, 0))
        bk_img = numpy.array(img_pil)
        cv2.imwrite('img2/img' + str(index) + '.jpg', bk_img)
        index += 1
        if index >= 99:
            return


work()
